package edu.pku.sei.modeler.uml.commands;

import org.eclipse.gef.commands.Command;

import edu.pku.sei.modeler.model.uml.Kernel.NamedElement;

/**
 * @author CrystalZhang created on 2008-3-9
 */

public class ChangeNameCommand extends Command {
	private NamedElement umlModelElement;

	private String oldName;

	private String newName;
	
	public ChangeNameCommand(NamedElement umlModelElement, String newName) {
		super("change name");
		this.umlModelElement = umlModelElement;
		this.oldName = umlModelElement.getName();
		this.newName = newName.trim();
		
	}

	@Override
	public boolean canExecute() {
		return umlModelElement != null;
	}

	@Override
	public void execute() {
		umlModelElement.setName(newName);
	}

	@Override
	public void undo() {
		umlModelElement.setName(oldName);
	}

}
